from django.forms.widgets import Textarea


class AnswersTextarea(Textarea):
    def __init__(self, attrs=None):
        new_attrs = {
            'class': 'answersTextField', # FIXME: This CSS class is used in admin, but it shouldn't be used in every form
            'rows': '5' # Likert scale is most commonly used and it has 5 choices
        }
        if attrs:
            new_attrs.update(attrs)
        super(AnswersTextarea, self).__init__(attrs=new_attrs)

    def render(self, name, value, attrs=None):
        if isinstance(value, (list, tuple)):
            value = '\n'.join(value)
        return super(AnswersTextarea, self).render(name, value, attrs=attrs)